// Estrutura para janela de Splash (welcome)
#ifndef SPLASH 
#define SPLASH

#include <GL/glut.h>
#include <stdlib.h>

#include "interfac.h"
#include "logo.h"
#include "minerva.h"
#include "miscfunc.h"
#include "messages.h"

int jansplash;
float alpha=0;
bool fume=false;

// Funcao redisplay da janela de entrada
void displaySplash (void)
{
  glClearColor (1.0, 1.0, 1.0, 1.0);
  glClear(GL_COLOR_BUFFER_BIT);
    
  glRasterPos2f(0,0);
  glDrawPixels( 500,400, GL_RGBA, GL_UNSIGNED_BYTE, logo);

  if(fume)
  {
	  glColor4f(0.8,0.8,0.8,alpha);
	  glBegin(GL_QUADS);
		glVertex2f(10,10);
		glVertex2f(10,390);
		glVertex2f(490,390);
		glVertex2f(490,10);
	  glEnd();
	  
	  glColor3f(0.0,0.0,0.0);
	  glLineWidth(2.5);
	  strokeOutput(0.3, 75.0, 350.0, MSG172);
	  strokeOutput(0.3, 75.0, 300.0, MSG173);

	  glLineWidth(1.5);
	  glColor3f(0.0,0.0,0.0);
	  strokeOutput(0.09, 440, 285,VERSAO);
	  strokeOutput(0.09, 440, 270,DATA);
	  	  
	  glLineWidth(5);
	  glBegin(GL_LINES);
	    glColor3f(0.0,1.0,0.0);
	    glVertex2f(25,255);
		glColor3f(1.0,1.0,0.0);
		glVertex2f(475,255);
		glColor3f(0.0,0.0,1.0);
		glVertex2f(25,105);
		glColor3f(1.0,1.0,1.0);
		glVertex2f(475,105);
	  glEnd();
	  
	  glRasterPos2f(17,125);
	  glDrawPixels( 100,110, GL_RGBA, GL_UNSIGNED_BYTE, minerva);

	  glColor3f(0.0,0.0,0.0);
	  glLineWidth(1.6);
	  strokeOutput(0.111, 267, 220, MSG175);
	  glLineWidth(2.7);
	  strokeOutput(0.28, 230, 175, MSG176);
	  glLineWidth(1.6);
	  strokeOutput(0.111, 267, 152, MSG177);
	  strokeOutput(0.111, 267, 135, MSG178);

	  glLineWidth(1.5);
	  strokeOutput(0.1, 250,70,MSG179);
	  strokeOutput(0.1, 250,40,MSG180);
  }

  glutSwapBuffers();
}


// funcao de reshape da janela de entrada
void reshapeSplash (int w, int h)
{
	glutReshapeWindow(500,400);
	glViewport (0, 0, (GLsizei) 500, (GLsizei) 400);
	glMatrixMode (GL_PROJECTION);
	glLoadIdentity ();
	gluOrtho2D (0.0, (GLdouble) 500, 0, (GLdouble) 400);
}


//destruidor
void destroiSplash(void)
{
	glutDestroyWindow(jansplash);
}


// keyboard callback
void keyboardSplash(unsigned char key, int x, int y)
{
	if (key!=0) 
	{
		if (fume) {destroiSplash();	interfaceCreate();}
		if (!fume)
		{
			fume=true;alpha=0.6;
			glutPostRedisplay();
		}
	}
}


void countdown1(int val)
{
	if(!fume)
	{
		fume=true;
		alpha=0.6;
		glutPostRedisplay();
	}
}

// mouse callback
void mouseSplash(int bot, int stat, int x, int y)
{
	if (bot==GLUT_LEFT_BUTTON && stat==GLUT_DOWN) 
	{

	if (fume) {destroiSplash();	interfaceCreate();}
	if (!fume)
	{
		fume=true;alpha=0.6;
		glutPostRedisplay();
	}
	}
}



// Contrutor da janela de entrada
void constroiSplash(void)
{
   glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGBA);
   glutInitWindowSize (500, 400); 
   glutInitWindowPosition (100, 100);
   jansplash=glutCreateWindow (MSG181);
   glutDisplayFunc(displaySplash); 
   glutReshapeFunc(reshapeSplash);
   glutMouseFunc(mouseSplash);
   glutKeyboardFunc(keyboardSplash);
   glutTimerFunc(30000, countdown1, 1);
   
   // ativa efeitos especiais
   glShadeModel (GL_SMOOTH);
   glEnable(GL_BLEND);
   glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
   glEnable(GL_POLYGON_SMOOTH);
   glEnable(GL_LINE_SMOOTH);
}


void welcome(int argc, char** argv)
{
	glutInit(&argc, argv);
	
	constroiSplash();

	glutMainLoop();
}

#endif
